package com.ycsj.goldmedalnewconcept.view;

import java.util.List;

import com.ycsj.goldmedalnewconcept.activity.MyQuanziActivity;
import com.ycsj.goldmedalnewconcept.bean.Commentlist;
import com.ycsj.goldmedalnewconcept.bean.EvaluationReply;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.R;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 *评论回复
 */
public class CommentsAdapter extends BaseAdapter {
    private Context context;
    private List<Commentlist> commentlist;

    public CommentsAdapter(Context context,List<Commentlist> commentlist) {
        this.context = context;
        this.commentlist = commentlist;
    }

    @Override
    public int getCount() {
        return commentlist.size();
    }

    @Override
    public Commentlist getItem(int position) {
        return commentlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_evaluatereply, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        
        holder.content = (TextView) convertView.findViewById(R.id.tv_content);
        holder.tv_name1 = (TextView) convertView.findViewById(R.id.tv_name1);
        holder.tv_name2 = (TextView) convertView.findViewById(R.id.tv_name2);
        holder.tv_huifu = (TextView) convertView.findViewById(R.id.tv_huifu);
       
        holder.tv_huifu.setVisibility(holder.tv_huifu.GONE);
        holder.content.setText(":"+commentlist.get(position).content);
        //自己评论自己
        if("".equals(commentlist.get(position).user_name)&&"".equals(commentlist.get(position).user_name2)){
        	holder.tv_name1.setText(SPUtil.getString(context, "name", ""));
        }
        //自己回复别人
        if("".equals(commentlist.get(position).user_name)&&!"".equals(commentlist.get(position).user_name2)){
        	holder.tv_name1.setText(SPUtil.getString(context, "name", ""));
        	holder.tv_name2.setText(commentlist.get(position).user_name2);
        	holder.tv_huifu.setVisibility(holder.tv_huifu.VISIBLE);
        }
        //别人回复别人
        if(!"".equals(commentlist.get(position).user_name)&&!"".equals(commentlist.get(position).user_name2)&&
        		!commentlist.get(position).user_name.equals(commentlist.get(position).user_name2)){
        	holder.tv_name1.setText(commentlist.get(position).user_name);
        	holder.tv_name2.setText(commentlist.get(position).user_name2);
        	holder.tv_huifu.setVisibility(holder.tv_huifu.VISIBLE);
        }
      //别人回复别人自己
        if(!"".equals(commentlist.get(position).user_name)&&
        		commentlist.get(position).user_name.equals(commentlist.get(position).user_name2)){
        	holder.tv_name1.setText(commentlist.get(position).user_name);
        }
      //别人回复自己
        if(!"".equals(commentlist.get(position).user_name)&&"".equals(commentlist.get(position).user_name2)){
        	holder.tv_name1.setText(commentlist.get(position).user_name);
        }
        
        return convertView;
    }

    class ViewHolder {
        
    	private TextView tv_name1;
    	private TextView tv_name2;
    	private TextView tv_huifu;
    	private TextView content;
        public ViewHolder(View convertView) {
        }
    }
}








